#include "keyboard.h"
#include "ui_keyboard.h"
#include "QPushButton"

Keyboard::Keyboard(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Keyboard)
{
    ui->setupUi(this);
    this->setWindowFlags( Qt::FramelessWindowHint );
    this->configKeys();
}

Keyboard::~Keyboard()
{
    delete ui;
}

void Keyboard::configKeys()
{
    for(uint i = 0; i<KEYS.size();i++){
        keys.append(new QPushButton(KEYS.at(i),this));
        keys[i]->setMaximumSize(50,50);
        keys[i]->setMinimumSize(50,50);

        keys[i]->setStyleSheet("QPushButton {background-color:rgb(200, 200, 200);}"
                               "QPushButton {border-radius:5px;}"
                               "QPushButton::pressed {background-color:rgb(100, 100, 100);}"
                               );
        // keys[i]->setStyleSheet(QString("QPushButton {border-radius:5px}"));

        if (i < 3)
            ui->gridLayout->addWidget(keys.at(i),0,i);
        if (i > 2 && i < 6)
            ui->gridLayout->addWidget(keys.at(i),1,i-3);
        if (i > 5 && i < 9)
            ui->gridLayout->addWidget(keys.at(i),2,i-6);
        if (i > 8)
            ui->gridLayout->addWidget(keys.at(i),3,i-9);

        connect(keys.at(i),&QPushButton::clicked,[this, i]{this->getButton(KEYS.at(i));});
    }
}

void Keyboard::getButton(QString btnCaption)
{
    emit buttonPressed(btnCaption);
}
